package com.zl.gen;

import com.zl.common.Result;
import com.zl.mapper.GeneratorMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 代码生成器
 * 
 * @author Mark sunlightcs@gmail.com
 */
@Service
public class SysGeneratorService {
	@Resource
	private GeneratorMapper generatorMapper;


	public Map<String, String> queryTable(String tableName) {
		return generatorMapper.queryTable(tableName);
	}

	public List<Map<String, String>> queryColumns(String tableName) {
		return generatorMapper.queryColumns(tableName);
	}

	public Result generatorCode(String[] tableNames) {

		try {
			for(String tableName : tableNames){
				//查询表信息
				Map<String, String> table = queryTable(tableName);
				//查询列信息
				List<Map<String, String>> columns = queryColumns(tableName);
				//生成代码
				return Result.success(GenUtils.generatorCode(table, columns));
			}
		} catch (Exception e) {
			return Result.error();
		}
		return Result.error();
	}
}
